import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { getConfig } from 'utils';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthModule } from './auth/auth.module';
import { UserInfoModule } from './user_info/user_info.module';
import { CompanyModule } from './company/company.module';
import { RecordCalcModule } from './record_calc/record_calc.module';
import { RecordLoginModule } from './record_login/record_login.module';
import { RecordPwdModule } from './record_pwd/record_pwd.module';
import { RecordCompanyModule } from './record_company/record_company.module';
import { RecordLogoutModule } from './record_logout/record_logout.module';
import { ConfigCalcModule } from './config_calc/config_calc.module';
import { CompanySubscriber } from './company/company.Subscriber';
import { MenuModule } from './menu/menu.module';
import { RecordMenuModule } from './record_menu/record_menu.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      ignoreEnvFile: true,
      isGlobal: true,
      load: [getConfig],
    }),
    TypeOrmModule.forRootAsync({
      useFactory: async (config: ConfigService) => {
        return {
          ...(await config.get('MYSQL_CONFIG')),
          entities: [__dirname + '/**/*.entity{.ts,.js}'],
          subscribers: [CompanySubscriber], // 消息订阅
        };
      },
      inject: [ConfigService],
    }),
    UserModule,
    AuthModule,
    UserInfoModule,
    CompanyModule,
    ConfigCalcModule,
    RecordCalcModule,
    RecordLoginModule,
    RecordLogoutModule,
    RecordPwdModule,
    RecordCompanyModule,
    MenuModule,
    RecordMenuModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
